<template>
  <div class="col-md-4">
    <form class="form-horizontal" @submit.prevent>
      <div class="form-group">
        <label>用户名</label>
        <input
          type="text"
          class="form-control"
          placeholder="用户名"
          v-model="name"
        />
      </div>
      <div class="form-group">
        <label>评论内容</label>
        <textarea
          class="form-control"
          rows="6"
          placeholder="评论内容"
          v-model="text"
        ></textarea>
      </div>
      <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
          <button type="submit" class="btn btn-default pull-right" @click="fn">
            提交
          </button>
        </div>
      </div>
    </form>
  </div>
</template>

<script>
export default {
  name: "AddComment",
  data() {
    return {
      name: "",
      text: "",
    };
  },
  props: ["list"],
  methods: {
    fn() {
      let obj = { userName: this.name, userText: this.text, id: Date.now() };
      if (this.name && this.text) {
        this.list.push(obj);
        this.name = "";
        this.text = "";
        return;
      }
      alert("请输入内容或用户名");
    },
  },
};
</script>

<style></style>